package org.basis.algorithm.recursion;

/**
 * 汉诺塔问题
 *
 * @author Mr_wenpan@163.com 2021/12/31 14:08
 */
public class Hanoi {

    public static void main(String[] args) {
//        System.out.println(1 % 2);
//        hanoi(3);
    }

    public int countHomogenous(String s) {
        if (s == null || s.length() > 1) {
            return 0;
        }
        int length = s.length();
        return length + process(s.toCharArray(), 0);
    }

    public int process(char[] chars, int i) {
        if (i >= chars.length) {
            return 1;
        }
        int res = 0;
        // 和后一个字符串是否相等
        res += process(chars, i);
        if (i + 1 < chars.length && chars[i] == chars[i + 1]) {
            res += process(chars, i + 1);
        }
        return res;
    }


    public static void print(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + "   ");
        }
        System.out.println();
    }

    public static void hanoi(int n) {
        if (n > 0) {
            func(n, "左", "中", "右");
        }
    }

    public static void func(int i, String start, String other, String end) {
        if (i == 1) {
            System.out.println("move 1 from " + start + " to " + end);
            return;
        }
        func(i - 1, start, end, other);
        System.out.println("move " + i + " from " + start + " to " + end);
        func(i - 1, other, start, end);
    }

//    public static void hanoi(int n) {
//        if (n > 0) {
//            func(n, n, "left", "mid", "right");
//        }
//    }
//
//    public static void func(int rest, int down, String from, String help, String to) {
//        if (rest == 1) {
//            System.out.println("move " + down + " from " + from + " to " + to);
//        } else {
//            func(rest - 1, down - 1, from, to, help);
//            func(1, down, from, help, to);
//            func(rest - 1, down - 1, help, from, to);
//        }
//    }

}
